"""
==================
ballista.responses
==================

The basic included ``Response`` types.

"""

class Response:
    """
    Response
    ========

    The basic action response class. Use this as a superclass for all possible responses.
    
    """
    def __init__(self, value, headers=(), status='200 OK'):
        """
        Response.__init__
        =================

        __init__(self, value, headers=()) -> Response instance
        Initialise the response by simply storing the sent value(s).
        
        """
        self.value, self.headers, self.status = value, headers, status

    def out(self):
        """
        Response.out
        ============

        out(self) -> string
        Return the output of the response.
        
        """
        return self.value

class TextResponse(Response):
    """
    TextResponse
    ============

    A ``Response`` subclass which is just here for convenience reasons, as it's a clone of Response.
    
    """

class RedirResponse(Response):
    """
    RedirResponse
    =============
    
    A basic HTTP redirection.
    
    """
    value = ''
    def __init__(self, location, permanent=False):
        """
        __init__(self, location, permanent=False)
        Initialise the redirection.
        
        """
        if permanent:
            self.status = '301 Moved Permanently'
        else:
            self.status = '302 Moved Temporarily'
        
        self.headers = [('Location', location)]
